package com.FQJ.stock.controller;

import com.FQJ.stock.pojo.domain.*;
import com.FQJ.stock.service.StockService;
import com.FQJ.stock.vo.resp.PageResult;
import com.FQJ.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/quot")
@Api(tags = "今日股票指数")
public class StockController {


	@Autowired
    private StockService stockService;

	//其它省略.....
    /**
     * 获取国内最新大盘指数
     * @return
     */
    @GetMapping("/index/all")
	@ApiOperation(value = "获取国内大盘数据")
    public R<List<InnerMarketDomain>> innerIndexAll(){
        return stockService.innerIndexAll();
    }

	/**
	 *需求说明: 获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据
	 * @return
	 */
	@GetMapping("/sector/all")
	@ApiOperation(value = "获取沪深两市板块最新数据")
	public R<List<StockBlockDomain>> sectorAll(){
		return stockService.sectorAllLimit();
	}


	@GetMapping("/external/index")
	@ApiOperation(value = "国外大盘数据")
	public R<List<OuterMarketDomain>>externalIndex(){
		return stockService.externalIndex();
	}


	@GetMapping("/stock/all")
	@ApiOperation(value = "获取股票交易分页信息")
	public R<PageResult> pageResultR(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page
		,@RequestParam(name = "pageSize",required = false,defaultValue = "20") Integer pageSize){
		return stockService.pageResultR(page,pageSize);
	}

	@GetMapping("stock/increase")
	@ApiOperation("涨幅榜功能")
	public R<List<StockUpdownDomain>>stockIncrease(){
		return stockService.stockIncrease();
	}
	/**
	 * 统计最新交易日下股票每分钟涨跌停的数量
	 * @return
	 */
	@GetMapping("/stock/updown/count")
	@ApiOperation("统计最新交易日下股票每分钟涨跌停的数量")
	public R<Map> getStockUpdownCount(){
		return stockService.getStockUpdownCount();
	}


	@GetMapping("/stock/export")
	@ApiOperation(value = "导入涨幅榜到excell表")
	public void excell(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
							@RequestParam(name = "pageSize",required = false,defaultValue = "20") Integer pageSize,
							HttpServletResponse response){
		stockService.pageResultR1(page,pageSize,response);
	}

	/**
	 * 成交量对比功能接口
	 */
	@ApiOperation(value = "成交量对比功能接口")
	@GetMapping("/stock/tradeAmt")
	public R<Map<String,List<Map>>> getCompareStockTradeAmt(){
		return stockService.getCompareStockTradeAmt();
	}

	/**
	 * 查询当前时间下股票的涨跌幅度区间统计功能
	 * 如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询点
	 * @return
	 */
	@GetMapping("/stock/updown")
	@ApiOperation(value = "查询当前时间下股票的涨跌幅度区间统计功能")
	public R<Map<String,Object>> getStockUpDown(){
		return stockService.stockUpDownScopeCount();
	}

	/**
	 * 功能描述：查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据；
	 *         如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询时间点
	 * @param code 股票编码
	 * @return
	 */
	@GetMapping("/stock/screen/time-sharing")
	@ApiOperation(value = "查询单个个股的分时行情数据，")
	public R<List<Stock4MinuteDomain>> stockScreenTimeSharing(@RequestParam("code") String code){
		return stockService.stockScreenTimeSharing(code);
	}


	/**
	 * 单个个股日K 数据查询 ，可以根据时间区间查询数日的K线数据
	 * @param stockCode 股票编码
	 */
	@GetMapping("/stock/screen/dkline")
	@ApiOperation(value = "单个个股日K 数据查询 ")
	public R<List<Stock4EvrDayDomain>> getDayKLinData(@RequestParam("code") String stockCode){
		return stockService.stockCreenDkLine(stockCode);
	}

}
